home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / ldapjdk.jar / netscape / ldap / util / MimeBase64Encoder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-13  |  1.9 KB  |  101 lines

  1. package netscape.ldap.util;
  2.  
  3. public final class MimeBase64Encoder extends MimeEncoder {
  4.    private int buf;
  5.    private int buf_bytes;
  6.    private byte[] line = new byte[74];
  7.    private int line_length;
  8.    private static final byte[] crlf = "\r\n".getBytes();
  9.    private static final byte[] map = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
  10.  
  11.    private final void encode_token() {
  12.       int var1 = this.line_length;
  13.       this.line[var1] = map[63 & this.buf >> 18];
  14.       this.line[var1 + 1] = map[63 & this.buf >> 12];
  15.       this.line[var1 + 2] = map[63 & this.buf >> 6];
  16.       this.line[var1 + 3] = map[63 & this.buf];
  17.       this.line_length += 4;
  18.       this.buf = 0;
  19.       this.buf_bytes = 0;
  20.    }
  21.  
  22.    private final void encode_partial_token() {
  23.       int var1 = this.line_length;
  24.       this.line[var1] = map[63 & this.buf >> 18];
  25.       this.line[var1 + 1] = map[63 & this.buf >> 12];
  26.       if (this.buf_bytes == 1) {
  27.          this.line[var1 + 2] = 61;
  28.       } else {
  29.          this.line[var1 + 2] = map[63 & this.buf >> 6];
  30.       }
  31.  
  32.       if (this.buf_bytes <= 2) {
  33.          this.line[var1 + 3] = 61;
  34.       } else {
  35.          this.line[var1 + 3] = map[63 & this.buf];
  36.       }
  37.  
  38.       this.line_length += 4;
  39.       this.buf = 0;
  40.       this.buf_bytes = 0;
  41.    }
  42.  
  43.    private final void flush_line(ByteBuf var1) {
  44.       var1.append(this.line, 0, this.line_length);
  45.       this.line_length = 0;
  46.    }
  47.  
  48.    public final void translate(ByteBuf var1, ByteBuf var2) {
  49.       byte[] var3 = var1.toBytes();
  50.       int var4 = var1.length();
  51.  
  52.       for(int var5 = 0; var5 < var4; ++var5) {
  53.          if (this.buf_bytes == 0) {
  54.             this.buf = this.buf & '\uffff' | var3[var5] << 16;
  55.          } else if (this.buf_bytes == 1) {
  56.             this.buf = this.buf & 16711935 | var3[var5] << 8 & '\uffff';
  57.          } else {
  58.             this.buf = this.buf & 16776960 | var3[var5] & 255;
  59.          }
  60.  
  61.          if (++this.buf_bytes == 3) {
  62.             this.encode_token();
  63.             if (this.line_length >= 72) {
  64.                var2.append(this.line, 0, this.line_length);
  65.                this.line_length = 0;
  66.             }
  67.          }
  68.  
  69.          if (var5 == var4 - 1) {
  70.             if (this.buf_bytes > 0 && this.buf_bytes < 3) {
  71.                this.encode_partial_token();
  72.             }
  73.  
  74.             if (this.line_length > 0) {
  75.                var2.append(this.line, 0, this.line_length);
  76.                this.line_length = 0;
  77.             }
  78.          }
  79.       }
  80.  
  81.       for(int var6 = 0; var6 < this.line.length; ++var6) {
  82.          this.line[var6] = 0;
  83.       }
  84.  
  85.    }
  86.  
  87.    public final void eof(ByteBuf var1) {
  88.       if (this.buf_bytes != 0) {
  89.          this.encode_partial_token();
  90.       }
  91.  
  92.       var1.append(this.line, 0, this.line_length);
  93.       this.line_length = 0;
  94.  
  95.       for(int var2 = 0; var2 < this.line.length; ++var2) {
  96.          this.line[var2] = 0;
  97.       }
  98.  
  99.    }
  100. }
  101.